package com.jx.controller.admin.system;

import com.github.pagehelper.PageInfo;
import com.jx.common.result.AjaxResult;
import com.jx.pojo.entity.system.User;
import com.jx.pojo.vo.system.UserVO;
import com.jx.service.system.UserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 用户管理
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;

    /**
     * 分页查询用户
     */
    @GetMapping("/listPage")
    public AjaxResult listPage(UserVO query) {
        PageInfo<User> page = userService.listPage(query);
        return AjaxResult.success(page);
    }

    /**
     * 保存用户
     */
    @PostMapping("/save")
    public AjaxResult save(@RequestBody User user) {
        userService.saveUser(user);
        return AjaxResult.success("保存成功");
    }

    /**
     * 删除用户
     */
    @DeleteMapping("/deleteById")
    public AjaxResult deleteById(@RequestParam("id") Integer id) {
        userService.removeById(id);
        return AjaxResult.success("删除成功");
    }

    /**
     * 获取详情
     */
    @GetMapping("/getById")
    public AjaxResult getById(Integer id) {
        User user = userService.getUserById(id);
        return AjaxResult.success(user);
    }


}
